/*
 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "notification_clone_bundle_info.h"
#include "ans_inner_errors.h"

using namespace testing::ext;
namespace OHOS {
namespace Notification {
constexpr const char *BUNDLE_INFO_NAME = "name";
constexpr const char *BUNDLE_INFO_APP_INDEX = "index";
constexpr const char *BUNDLE_INFO_SLOT_FLAGS = "slotFlags";
constexpr const char *BUNDLE_INFO_SHOW_BADGE = "badge";
constexpr const char *BUNDLE_INFO_ENABLE_NOTIFICATION = "enable";
constexpr const char *BUNDLE_INFO_ENABLEDSTATE_NOTIFICATION = "enabledState";
constexpr const char *BUNDLE_INFO_SLOT_AUTHSTATUS = "slotAuthorized";
constexpr const char *BUNDLE_INFO_SLOT_LIST = "slotList";
constexpr const char *BUNDLE_INFO_SLOT_TYPE = "slotType";
constexpr const char *BUNDLE_INFO_SLOT_ENABLE = "slotEnable";
constexpr const char *BUNDLE_INFO_SLOT_CONTROL = "slotControl";
constexpr const char *BUNDLE_INFO_POP_DIALOG = "popDialog";
constexpr const char *BUNDLE_INFO_RINGTONE_INFO = "ringtone";
constexpr const char *BUNDLE_INFO_SILENT_REMINDER = "enabledSilentReminder";
class NotificationCloneBundleInfoTest : public testing::Test {
public:
    static void SetUpTestCase() {};
    static void TearDownTestCase() {};
    void SetUp() {};
    void TearDown() {};
};

/**
 * @tc.name: SetBundleName_00001
 * @tc.desc: Test SetBundleName parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetBundleName_00001, Function | SmallTest | Level1)
{
    std::string bundleName = "BundleName";
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetBundleName(bundleName);
    EXPECT_EQ(rrc->GetBundleName(), bundleName);
}

/**
 * @tc.name: SetAppIndex_00001
 * @tc.desc: Test SetAppIndex parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetAppIndex_00001, Function | SmallTest | Level1)
{
    int32_t appIndex = 1;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetAppIndex(appIndex);
    EXPECT_EQ(rrc->GetAppIndex(), appIndex);
}

/**
 * @tc.name: SetUid_00001
 * @tc.desc: Test SetUid parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetUid_00001, Function | SmallTest | Level1)
{
    int32_t uid = 1;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetUid(uid);
    EXPECT_EQ(rrc->GetUid(), uid);
}

/**
 * @tc.name: SetSlotFlags_00001
 * @tc.desc: Test SetUid parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetSlotFlags_00001, Function | SmallTest | Level1)
{
    int32_t slotFlags = 1;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetSlotFlags(slotFlags);
    EXPECT_EQ(rrc->GetSlotFlags(), slotFlags);
}

/**
 * @tc.name: SetIsShowBadge_00001
 * @tc.desc: Test SetIsShowBadge parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetIsShowBadge_00001, Function | SmallTest | Level1)
{
    bool isShowBadge = true;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetIsShowBadge(isShowBadge);
    EXPECT_EQ(rrc->GetIsShowBadge(), isShowBadge);
}

/**
 * @tc.name: SetEnableNotification_00001
 * @tc.desc: Test SetEnableNotification parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetEnableNotification_00001, Function | SmallTest | Level1)
{
    NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetEnableNotification(enabledNotification);
    EXPECT_EQ(rrc->GetEnableNotification(), enabledNotification);
}

/**
 * @tc.name: AddSlotInfo_00001
 * @tc.desc: Test AddSlotInfo parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, AddSlotInfo_00001, Function | SmallTest | Level1)
{
    NotificationCloneBundleInfo::SlotInfo slotInfo;
    slotInfo.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
    slotInfo.enable_ = true;
    slotInfo.isForceControl_ = true;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->AddSlotInfo(slotInfo);
    rrc->AddSlotInfo(slotInfo);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 1);
}

/**
 * @tc.name: SetExtensionSubscriptionInfos_00001
 * @tc.desc: Test SetExtensionSubscriptionInfos parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetExtensionSubscriptionInfos_00001, Function | SmallTest | Level1)
{
    std::vector<sptr<NotificationExtensionSubscriptionInfo>> infos;
    infos.emplace_back(new (std::nothrow) NotificationExtensionSubscriptionInfo());
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->SetExtensionSubscriptionInfos(infos);
    EXPECT_EQ(rrc->GetExtensionSubscriptionInfos().size(), 1);
}

/**
 * @tc.name: SubscriptionInfosFromJson_00001
 * @tc.desc: Test SubscriptionInfosFromJson parameters with nullptr.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SubscriptionInfosFromJson_00001, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->SubscriptionInfosFromJson(jsonObject);
    EXPECT_TRUE(rrc->GetExtensionSubscriptionInfos().empty());
}

/**
 * @tc.name: SubscriptionInfosFromJson_00002
 * @tc.desc: Test SubscriptionInfosFromJson parameters without array.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SubscriptionInfosFromJson_00002, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json{
        "extensionSubscriptionInfo", "test"
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->SubscriptionInfosFromJson(jsonObject);
    EXPECT_TRUE(rrc->GetExtensionSubscriptionInfos().empty());
}

/**
 * @tc.name: SubscriptionInfosFromJson_00003
 * @tc.desc: Test SubscriptionInfosFromJson parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SubscriptionInfosFromJson_00003, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json{
        {"extensionSubscriptionInfo", {
            {
                {"addr", "addr1"},
                {"isHfp", true},
                {"type", 0}
            }
        }}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->SubscriptionInfosFromJson(jsonObject);
    EXPECT_EQ(rrc->GetExtensionSubscriptionInfos().size(), 1);
}

/**
 * @tc.name: SetExtensionSubscriptionBundles_00001
 * @tc.desc: Test SetExtensionSubscriptionBundles
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SetExtensionSubscriptionBundles_00001, Function | SmallTest | Level1)
{
    std::vector<sptr<NotificationBundleOption>> bundles;
    sptr<NotificationBundleOption> bundle = new NotificationBundleOption("test", 1000);
    bundles.push_back(bundle);
    
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetExtensionSubscriptionBundles(bundles);
    
    auto result = rrc->GetExtensionSubscriptionBundles();
    EXPECT_EQ(result.size(), 1);
    EXPECT_EQ(result[0]->GetBundleName(), "test");
    EXPECT_EQ(result[0]->GetUid(), 1000);
}

/**
 * @tc.name: GetExtensionSubscriptionBundles_00001
 * @tc.desc: Test GetExtensionSubscriptionBundles
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, GetExtensionSubscriptionBundles_00001, Function | SmallTest | Level1)
{
    auto notificationCloneBundleInfo = std::make_shared<NotificationCloneBundleInfo>();
    auto result = notificationCloneBundleInfo->GetExtensionSubscriptionBundles();
    EXPECT_EQ(result.size(), 0);
}

/**
 * @tc.name: ToJson_00001
 * @tc.desc: Test ToJson parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ToJson_00001, Function | SmallTest | Level1)
{
    std::string bundleName = "BundleName";
    int32_t appIndex = 1;
    int32_t uid = 1;
    int32_t slotFlags = 1;
    bool isShowBadge = true;
    bool hasPoppedDialog = true;
    NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
    NotificationCloneBundleInfo::SlotInfo slotInfo;
    slotInfo.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
    slotInfo.enable_ = true;
    slotInfo.isForceControl_ = true;
    auto extensionBundle = new NotificationCloneBundleInfo();
    extensionBundle->SetBundleName("ExtensionBundle");
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetBundleName(bundleName);
    rrc->SetAppIndex(appIndex);
    rrc->SetUid(uid);
    rrc->SetSlotFlags(slotFlags);
    rrc->SetIsShowBadge(isShowBadge);
    rrc->SetHasPoppedDialog(hasPoppedDialog);
    rrc->SetEnableNotification(enabledNotification);
    rrc->AddSlotInfo(slotInfo);
    std::vector<std::shared_ptr<NotificationCloneBundleInfo>> extensionBundles;
    extensionBundles.push_back(std::make_shared<NotificationCloneBundleInfo>(*extensionBundle));
    nlohmann::json jsonObject;
    EXPECT_EQ(jsonObject.is_null(), true);
    EXPECT_EQ(jsonObject.is_object(), false);
    rrc->FromJson(jsonObject);
    rrc->ToJson(jsonObject);
    EXPECT_EQ(jsonObject.is_object(), true);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 1);
    rrc->FromJson(jsonObject);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 2);
    EXPECT_EQ(rrc->GetBundleName(), bundleName);
    EXPECT_EQ(rrc->GetAppIndex(), appIndex);
    EXPECT_EQ(rrc->GetUid(), uid);
    EXPECT_EQ(rrc->GetSlotFlags(), slotFlags);
    EXPECT_EQ(rrc->GetIsShowBadge(), isShowBadge);
    EXPECT_EQ(rrc->GetHasPoppedDialog(), hasPoppedDialog);
    EXPECT_EQ(rrc->GetEnableNotification(), enabledNotification);
    delete extensionBundle;
}

/**
 * @tc.name: ToJson_00002
 * @tc.desc: Test ToJson parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ToJson_00002, Function | SmallTest | Level1)
{
    std::string bundleName = "BundleName";
    int32_t appIndex = 1;
    int32_t uid = 1;
    int32_t slotFlags = 1;
    bool isShowBadge = true;
    NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
    std::vector<sptr<NotificationExtensionSubscriptionInfo>> infos;
    auto type = NotificationConstant::SubscribeType::BLUETOOTH;
    infos.emplace_back(new (std::nothrow) NotificationExtensionSubscriptionInfo("addr", type));
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetBundleName(bundleName);
    rrc->SetAppIndex(appIndex);
    rrc->SetUid(uid);
    rrc->SetSlotFlags(slotFlags);
    rrc->SetIsShowBadge(isShowBadge);
    rrc->SetEnableNotification(enabledNotification);
    rrc->SetExtensionSubscriptionInfos(infos);
    nlohmann::json jsonObject;
    EXPECT_EQ(jsonObject.is_null(), true);
    EXPECT_EQ(jsonObject.is_object(), false);
    rrc->FromJson(jsonObject);
    rrc->ToJson(jsonObject);
    EXPECT_EQ(jsonObject.is_object(), true);
    EXPECT_EQ(rrc->GetExtensionSubscriptionInfos().size(), 1);
}

/**
 * @tc.name: ToJson_00003
 * @tc.desc: Test ToJson parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ToJson_00003, Function | SmallTest | Level1)
{
    std::string bundleName = "BundleName";
    int32_t appIndex = 1;
    int32_t uid = 1;
    int32_t slotFlags = 1;
    bool isShowBadge = true;
    NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_ON;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetBundleName(bundleName);
    rrc->SetAppIndex(appIndex);
    rrc->SetUid(uid);
    rrc->SetSlotFlags(slotFlags);
    rrc->SetIsShowBadge(isShowBadge);
    rrc->SetEnableNotification(enabledNotification);
    nlohmann::json jsonObject;
    EXPECT_EQ(jsonObject.is_null(), true);
    EXPECT_EQ(jsonObject.is_object(), false);
    rrc->ToJson(jsonObject);
    rrc->FromJson(jsonObject);
    EXPECT_EQ(jsonObject.is_object(), true);
    EXPECT_EQ(rrc->GetEnableNotification(), enabledNotification);
}

/**
 * @tc.name: Dump_00001
 * @tc.desc: Test Dump parameters.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, Dump_00001, Function | SmallTest | Level1)
{
    std::string bundleName = "BundleName";
    int32_t appIndex = 1;
    int32_t uid = 1;
    int32_t slotFlags = 1;
    bool isShowBadge = true;
    bool hasPoppedDialog = true;
    NotificationConstant::SWITCH_STATE enabledNotification = NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON;
    NotificationCloneBundleInfo::SlotInfo slotInfo;
    slotInfo.slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
    slotInfo.enable_ = true;
    slotInfo.isForceControl_ = true;
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    rrc->SetBundleName(bundleName);
    rrc->SetAppIndex(appIndex);
    rrc->SetUid(uid);
    rrc->SetSlotFlags(slotFlags);
    rrc->SetIsShowBadge(isShowBadge);
    rrc->SetHasPoppedDialog(hasPoppedDialog);
    rrc->SetEnableNotification(enabledNotification);
    rrc->AddSlotInfo(slotInfo);
    sptr<NotificationRingtoneInfo> ringtoneInfo = new NotificationRingtoneInfo(
        NotificationConstant::RingtoneType::RINGTONE_TYPE_LOCAL, "title", "fileName", "uri");
    rrc->AddRingtoneInfo(ringtoneInfo);
    std::string dumpInfo;
    EXPECT_EQ(dumpInfo.size(), 0);
    std::string slotDump = "{";
    for (auto& slot : rrc->GetSlotInfo()) {
        slotDump += slot.Dump();
        slotDump += ",";
    }
    slotDump += "}";
    std::string ringtoneDump = ringtoneInfo->Dump();
    dumpInfo += "CloneBundle{ name = " + bundleName +
            ", index = " + std::to_string(appIndex) +
            ", uid = " + std::to_string(uid) +
            ", slotFlags = " + std::to_string(slotFlags) +
            ", ShowBadge = " + std::to_string(isShowBadge) +
            ", popDialog = " + std::to_string(hasPoppedDialog) +
            ", isEnabled = " + std::to_string(static_cast<int32_t>(enabledNotification)) +
            ", slotsInfo = " + slotDump +
            ", ringtone = " + ringtoneDump +
            ", silentReminderEnabled = 0" +
            " }";
    EXPECT_EQ(rrc->Dump(), dumpInfo);
}

/**
 * @tc.name: SubscriptionBundlesFromJson_00001
 * @tc.desc: Test SubscriptionBundlesFromJson with non-empty array.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SubscriptionBundlesFromJson_00001, Function | SmallTest | Level1)
{
    auto bundleInfo = std::make_shared<NotificationCloneBundleInfo>();
    
    nlohmann::json jsonObject = {
        {"extensionSubscriptionBundles", {
            {{"bundleName", "com.example.app1"}, {"uid", 1001}},
            {{"bundleName", "com.example.app2"}, {"uid", 1002}}
        }}
    };

    bundleInfo->SubscriptionBundlesFromJson(jsonObject);
    auto result = bundleInfo->GetExtensionSubscriptionBundles();
    EXPECT_EQ(result.size(), 2);
    EXPECT_EQ(result[0]->GetBundleName(), "com.example.app1");
    EXPECT_EQ(result[0]->GetUid(), 1001);
    EXPECT_EQ(result[1]->GetBundleName(), "com.example.app2");
    EXPECT_EQ(result[1]->GetUid(), 1002);
}

/**
 * @tc.name: SubscriptionBundlesFromJson_00002
 * @tc.desc: Test SubscriptionBundlesFromJson with empty array.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SubscriptionBundlesFromJson_00002, Function | SmallTest | Level1)
{
    auto bundleInfo = std::make_shared<NotificationCloneBundleInfo>();
    nlohmann::json jsonObject = {
        {"extensionSubscriptionBundles", nlohmann::json::array()}
    };
    
    bundleInfo->SubscriptionBundlesFromJson(jsonObject);
    EXPECT_EQ(bundleInfo->GetExtensionSubscriptionBundles().size(), 0);
}

/**
 * @tc.name: ExtensionSubscriptionFromJson_00001
 * @tc.desc: Test ExtensionSubscriptionFromJson when BUNDLE_INFO_SUBSCRIPTION_ENABLED is missing.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ExtensionSubscriptionFromJson_00001, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json{
        {"validKey", 123}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->ExtensionSubscriptionFromJson(jsonObject);
    EXPECT_EQ(rrc->GetEnabledExtensionSubscription(), NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF);
}

/**
 * @tc.name: ExtensionSubscriptionFromJson_00002
 * @tc.desc: Test ExtensionSubscriptionFromJson when BUNDLE_INFO_SUBSCRIPTION_ENABLED not a number.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ExtensionSubscriptionFromJson_00002, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json{
        {"enableExtensionSubscription", "not_a_number"}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->ExtensionSubscriptionFromJson(jsonObject);
    EXPECT_EQ(rrc->GetEnabledExtensionSubscription(), NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF);
}

/**
 * @tc.name: ExtensionSubscriptionFromJson_00003
 * @tc.desc: Test ExtensionSubscriptionFromJson when BUNDLE_INFO_SUBSCRIPTION_ENABLED equals CONST_ENABLE_INT.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ExtensionSubscriptionFromJson_00003, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json{
        {"enableExtensionSubscription", 1}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->ExtensionSubscriptionFromJson(jsonObject);
    EXPECT_EQ(rrc->GetEnabledExtensionSubscription(), NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON);
}

/**
 * @tc.name: ExtensionSubscriptionFromJson_00004
 * @tc.desc: Test ExtensionSubscriptionFromJson when BUNDLE_INFO_SUBSCRIPTION_ENABLED not equal to CONST_ENABLE_INT.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, ExtensionSubscriptionFromJson_00004, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json{
        {"enableExtensionSubscription", 0}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->ExtensionSubscriptionFromJson(jsonObject);
    EXPECT_EQ(rrc->GetEnabledExtensionSubscription(), NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF);
}

/**
 * @tc.name: SlotsFromJson_00001
 * @tc.desc: Test SlotsFromJson when json object does not contain keys.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SlotsFromJson_00001, Function | SmallTest | Level1)
{
    nlohmann::json jsonArray = nlohmann::json::array();
    jsonArray.emplace_back(nlohmann::json::object());
    nlohmann::json jsonObject = nlohmann::json {
        {BUNDLE_INFO_SLOT_LIST, jsonArray}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->SlotsFromJson(jsonObject);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 1);
}

/**
 * @tc.name: SlotsFromJson_00002
 * @tc.desc: Test SlotsFromJson when json object contains keys and has wrong type.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, SlotsFromJson_00002, Function | SmallTest | Level1)
{
    nlohmann::json jsonArray = nlohmann::json::array();
    nlohmann::json slotJson = nlohmann::json::object();
    slotJson[BUNDLE_INFO_SLOT_TYPE] = 0;
    slotJson[BUNDLE_INFO_SLOT_ENABLE] = "123";
    slotJson[BUNDLE_INFO_SLOT_CONTROL] = "123";
    slotJson[BUNDLE_INFO_SLOT_AUTHSTATUS] = "123";
    jsonArray.emplace_back(slotJson);
    nlohmann::json jsonObject = nlohmann::json {
        {BUNDLE_INFO_SLOT_LIST, jsonArray}
    };
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->SlotsFromJson(jsonObject);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 1);
}

/**
 * @tc.name: FromJson_00001
 * @tc.desc: Test SlotsFromJson when json object does not contain keys.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, FromJson_00001, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json::object();
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->FromJson(jsonObject);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 0);
}

/**
 * @tc.name: FromJson_00002
 * @tc.desc: Test FromJson when json object contains keys and has wrong type.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, FromJson_00002, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json::object();
    jsonObject[BUNDLE_INFO_NAME] = 1;
    jsonObject[BUNDLE_INFO_APP_INDEX] = "123";
    jsonObject[BUNDLE_INFO_SLOT_FLAGS] = "123";
    jsonObject[BUNDLE_INFO_SHOW_BADGE] = "123";
    jsonObject[BUNDLE_INFO_POP_DIALOG] = "123";
    jsonObject[BUNDLE_INFO_ENABLE_NOTIFICATION] = "123";
    jsonObject[BUNDLE_INFO_ENABLEDSTATE_NOTIFICATION] = "123";
    jsonObject[BUNDLE_INFO_SILENT_REMINDER] = "123";
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->FromJson(jsonObject);
    EXPECT_EQ(rrc->GetSlotInfo().size(), 0);
}

/**
 * @tc.name: RingtoneFromJson_00001
 * @tc.desc: Test SlotsFromJson when json object contains keys.
 * @tc.type: FUNC
 * @tc.require: issue
 */
HWTEST_F(NotificationCloneBundleInfoTest, RingtoneFromJson_00001, Function | SmallTest | Level1)
{
    nlohmann::json jsonObject = nlohmann::json::object();
    jsonObject[BUNDLE_INFO_RINGTONE_INFO] = "{}";
    auto rrc = std::make_shared<NotificationCloneBundleInfo>();
    ASSERT_NE(rrc, nullptr);
    rrc->RingtoneFromJson(jsonObject);
    EXPECT_NE(rrc->GetRingtoneInfo(), nullptr);
}
}
}
